package org.jeecg.modules.hc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.hc.entity.HcAliRefund;
import org.jeecg.modules.hc.service.IHcAliRefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

 /**
 * @Description: 支付宝退款
 * @Author: jeecg-boot
 * @Date:   2023-01-12
 * @Version: V1.0
 */
@Api(tags="支付宝退款")
@RestController
@RequestMapping("/hc/hcAliRefund")
@Slf4j
public class HcAliRefundController extends JeecgController<HcAliRefund, IHcAliRefundService> {
	@Autowired
	private IHcAliRefundService hcAliRefundService;

	/**
	 * 分页列表查询
	 *
	 * @param hcAliRefund
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "支付宝退款-分页列表查询")
//	@ApiOperation(value="支付宝退款-分页列表查询", notes="支付宝退款-分页列表查询")
//	@GetMapping(value = "/list")
	public Result<IPage<HcAliRefund>> queryPageList(HcAliRefund hcAliRefund,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<HcAliRefund> queryWrapper = QueryGenerator.initQueryWrapper(hcAliRefund, req.getParameterMap());
		Page<HcAliRefund> page = new Page<HcAliRefund>(pageNo, pageSize);
		IPage<HcAliRefund> pageList = hcAliRefundService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 *   添加
	 *
	 * @param hcAliRefund
	 * @return
	 */
//	@AutoLog(value = "支付宝退款-添加")
//	@ApiOperation(value="支付宝退款-添加", notes="支付宝退款-添加")
	//@RequiresPermissions("org.jeecg.modules:hc_ali_refund:add")
//	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody HcAliRefund hcAliRefund) {
		hcAliRefundService.save(hcAliRefund);
		return Result.OK("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param hcAliRefund
	 * @return
	 */
//	@AutoLog(value = "支付宝退款-编辑")
//	@ApiOperation(value="支付宝退款-编辑", notes="支付宝退款-编辑")
	//@RequiresPermissions("org.jeecg.modules:hc_ali_refund:edit")
//	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody HcAliRefund hcAliRefund) {
		hcAliRefundService.updateById(hcAliRefund);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
//	@AutoLog(value = "支付宝退款-通过id删除")
//	@ApiOperation(value="支付宝退款-通过id删除", notes="支付宝退款-通过id删除")
	//@RequiresPermissions("org.jeecg.modules:hc_ali_refund:delete")
//	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		hcAliRefundService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
//	@AutoLog(value = "支付宝退款-批量删除")
//	@ApiOperation(value="支付宝退款-批量删除", notes="支付宝退款-批量删除")
	//@RequiresPermissions("org.jeecg.modules:hc_ali_refund:deleteBatch")
//	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.hcAliRefundService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "支付宝退款-通过id查询")
//	@ApiOperation(value="支付宝退款-通过id查询", notes="支付宝退款-通过id查询")
//	@GetMapping(value = "/queryById")
	public Result<HcAliRefund> queryById(@RequestParam(name="id",required=true) String id) {
		HcAliRefund hcAliRefund = hcAliRefundService.getById(id);
		if(hcAliRefund==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(hcAliRefund);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param hcAliRefund
    */
    //@RequiresPermissions("org.jeecg.modules:hc_ali_refund:exportXls")
//    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, HcAliRefund hcAliRefund) {
        return super.exportXls(request, hcAliRefund, HcAliRefund.class, "支付宝退款");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("hc_ali_refund:importExcel")
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, HcAliRefund.class);
    }

}
